package com.yyaccp.itrip.auth.service;

import com.yyaccp.itrip.utils.RedisAPI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

/**
 * @author 天天向上 （john.yi@qq.com）
 * @date 2020/11/17.
 */
@Service
public class MailService {
    @Autowired
    private JavaMailSender javaMailSender;
    @Autowired
    private RedisAPI redisAPI;

    public void send(String code, String to, String subject, String content) {
        SimpleMailMessage mail = new SimpleMailMessage();
        mail.setFrom("11591198@qq.com");
        mail.setTo(to);
        mail.setSubject(subject);
        mail.setText(content);
        javaMailSender.send(mail);
        System.out.println("发送成功");
        redisAPI.setex(to, 30 * 60, code);
    }

}
